#include "MatchProcParamCollectResponseModel.h"
namespace MesModel {
MatchProcParamCollectResponseModel::MatchProcParamCollectResponseModel(QString factoryNo, QString transId, QDateTime eventTime, QString resultCode, QList<MatchProcParamCollectResponsePcuInfo> pcuInfo)
    :factoryNo(factoryNo),transId(transId),eventTime(eventTime),resultCode(resultCode),pcuInfo(pcuInfo){}

void MatchProcParamCollectResponseModel::fromJson(const QJsonObject &json)
{
    factoryNo = json["factoryNo"].toString();
    transId = json["transId"].toString();
    eventTime = QDateTime::fromString(json["eventTime"].toString());
    resultCode = json["resultCode"].toString();
    const auto pcu_info_list = json["pcuInfo"].toArray();
    for(const auto& item: pcu_info_list)
    {
        MatchProcParamCollectResponsePcuInfo pcu_info;
        pcu_info.fromJson(item.toObject());
        pcuInfo.append(pcu_info);
    }

}

QJsonObject MatchProcParamCollectResponseModel::toJson() const
{
    QJsonObject json;
    json["factoryNo"] = factoryNo;
    int randomNumber = QRandomGenerator::global()->bounded(10000,100000);
    json["transId"] = QString("%1%2").arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmssSSS")).arg(randomNumber);
    json["eventTime"]=QDateTime::currentDateTime().toString("yyyy-mm-dd hh:mm:ss");
    json["resultCode"]=resultCode;

    QJsonArray pcu_info_array;
    for(const auto& item:pcuInfo)
    {
        pcu_info_array.append(item.toJson());
    }
    json["pcuInfo"] = pcu_info_array;
    return json;
}


MatchProcParamCollectResponsePcuInfo::MatchProcParamCollectResponsePcuInfo(QString locationNo, QString pcu, QString resultMsg)
    :locationNo(locationNo),pcu(pcu),resultMsg(resultMsg)

{

}

void MatchProcParamCollectResponsePcuInfo::fromJson(const QJsonObject &json)
{
    pcu = json["pcu"].toString();
    locationNo = json["locationNo"].toString();
    resultMsg = json["resultMsg"].toString();
}

QJsonObject MatchProcParamCollectResponsePcuInfo::toJson() const
{
    QJsonObject json;
    json["pcu"]=pcu;
    json["locationNo"] = locationNo;
    json["resultMsg"] = resultMsg;

    return json;
}

}
